package org.eenie.commonlib.ui.bento.components.banner

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import cn.bingoogolapple.bgabanner.BGABanner
import com.yelp.android.bento.core.ComponentViewHolder
import com.yelp.android.bento.utils.inflate
import org.eenie.commonlib.R
import org.eenie.commonlib.exts.load

class BannerHolder<P : BGABanner.Delegate<ImageView, T>, T : IBannerData> : ComponentViewHolder<P, List<T>>(), BGABanner.Adapter<ImageView, T> {

    private lateinit var mBanner: BGABanner


    override fun bind(presenter: P, element: List<T>) {
        println("bind")

        mBanner.setData(element, ArrayList())
        mBanner.setDelegate(presenter)

    }

    override fun inflate(parent: ViewGroup): View {

        println("inflate")
        val itemView: View = parent.inflate(R.layout.holder_banner)
        mBanner = itemView.findViewById(R.id.lay_banner)
        mBanner.setAdapter(this)
        return itemView
    }


    override fun fillBannerItem(banner: BGABanner?, itemView: ImageView?, model: T?, position: Int) {
        model?.let { itemView?.load(it.imgUrl()) }
    }


}